<template>
  <div class="evaluation-container">
    <userHeader/>
    <div class="breadClum">
      <span>
          <router-link :to="{path:'/pageIndex'}"><a class="bread1">当前位置：首页  >  </a></router-link>
          <router-link :to="{path:'/comment'}"><a class="bread2">内控评价 ></a></router-link>
          <a class="bread2">审核评价报告</a>
      </span>
    </div>
    <div v-if="evaluationListArray.length>0">
      <evaluation-list  v-if="isShowDialog"  @selectReport="selectReport" :isShow.sync="isShow" :evaluationList=evaluationListArray  @selectEvaluationState="changeEvaluationState"></evaluation-list>
        <iframe :src=src frameborder="0" width="100%" height="600"></iframe>

      <div class="evaultion_area">
        <el-form :model="form"  ref="editorForm" :rules="rules">
          <el-form-item label="审核标识" :label-width="formLabelWidth" prop="audit_state">
            <el-radio v-model="form.audit_state" label="1">通过审核</el-radio>
            <el-radio v-model="form.audit_state" label="2">不通过审核</el-radio>
          </el-form-item>
          <div class="form-shenhe-menber">
            <el-form-item label="审核人员" :label-width="formLabelWidth">
              <el-input v-model="form.auditor"  readonly=""></el-input>
            </el-form-item>
            <el-form-item label="审核日期" :label-width="formLabelWidth" >
              <el-input v-model="form.audit_time"  readonly></el-input>
            </el-form-item>
          </div>
          <el-form-item label="审核意见" :label-width="formLabelWidth" prop="audit_opinion">
            <el-input type="textarea" v-model="form.audit_opinion" autocomplete="off"></el-input>
          </el-form-item>

        </el-form>
      </div>
      <div class="e-confirm">
        <el-button type="primary" @click="confirmModifyUser('editorForm')">确 定</el-button>
      </div>
    </div>
  <div v-else>
    暂无需要审核的报告,请稍后再试
  </div>
    <!--<iframe :src="https://view.officeapps.live.com/op/view.aspx?src=" frameborder="0" width="100%" height="600"></iframe>-->
    <!--<div class="edit-container">-->
      <!--<div class="edit-header" style="margin-bottom:20px;">-->
          <!--<el-button  type="primary" size="small"  @click="readEvaluation">预览</el-button>-->
          <!--<el-button  type="primary" size="small"  @click="saveEvaluation">保存</el-button>-->
      <!--</div>-->
    <!--</div>-->


  </div>
</template>
<script>
  import userHeader from '@/components/header.vue'
  import evaluationList from '@/components/evaluationList.vue'
  export default ({
    data() {
        var checkState=(rule, value, callback) => {
          if (!value ) {
            callback(new Error('请选择审核标识'));
          } else {
            callback();
          }
        };
      var checkAuditor=(rule, value, callback) => {
        console.log(value)
        if (!value) {
          callback(new Error('请选择审核人员'));
        } else {
          callback();
        }
      };
      var checkAudit_time=(rule, value, callback) => {

        if (!value ) {
          callback(new Error('请选择审核时间'));
        } else {
          callback();
        }
      };
      var checkAudit_opinion=(rule, value, callback) => {
        if (!value ) {
          callback(new Error('请填写审核意见'));
        } else {
          callback();
        }
      };
      return {
        total_messages:[],
        totalOaMessage:[],
        isShowDialog:true,
        isShow:true,
        evaluationListArray:[],
        formLabelWidth:'112px',
        evaplan_type_id:'',
        form:{},
        auditorId:'',
        auditTime:'',
        src:'',
        resultData:{},
        rules: {
          audit_state: [
            { required: true,validator:checkState}
          ],
          auditor:[
            { required: true,validator:checkAuditor}
          ],
          audit_time:[
            { required: true,validator:checkAudit_time}
          ],
          audit_opinion:[
            { required: true,validator:checkAudit_opinion}
          ],
        },
      }
    },
    components: {
      userHeader,
      evaluationList
    },
    computed: {},
    methods:{
      close(){
        this.$alert("请先选择评价类型",'提示',{
          confirmButtonText: '确定',
          callback: action => {
            this.$router.go(-1)
          }
        });
      },
      selectReport(data){
       console.log(data);
       this.evaplan_type_id=data;
        this.getDetail(data);
      },
      changeEvaluationState(mes){
        console.log(mes)

      },
      readEvaluation(){

      },
      saveEvaluation(){

      },
      initData(){
          let that =this;
        this.axios.get('/api/v1/flow/evaplantypeflat')
          .then((res)=>{
            if(res.data.code==0){
              console.log(res.data)
              this.evaluationListArray =res.data.data;
              if(res.data.data.length==0){
                this.$alert("当前暂无需要审核的报告，请先添加报告后再进行审核",'提示',{
                  confirmButtonText: '确定',
                  callback: action => {
                    that.$router.go(-1)
                  }
                });
              }

            }
          })
      },
//      获取评价报告审核人员信息和审核时间
      getDetail(data){
        this.axios.get('/api/v1/flow/evaluationreportaudit/'+`${data}`)
          .then((res)=>{
            if(res.data.code==0){
              this.auditorId =res.data.data.auditor;
              this.auditTime =  parseInt(new Date(res.data.data.audit_time).getTime()/1000);
              this.resultData =res.data.data;
              console.log(window.location.host);
              this.src="https://view.officeapps.live.com/op/view.aspx?src="+window.location.host+res.data.data.evareport_path;
              this.form={
                auditor:res.data.data.real_name,
                audit_time:res.data.data.audit_time
              };
            }else{
                this.$alert(res.data.message,'提示',{
                  confirmButtonText: '确定',
                  callback: action => {
                    this.$router.go(-1)
                  }
                })
            }
          })
      },
      confirmModifyUser(formName){
        let that =this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.axios.post('/api/v1/flow/evaluationreportaudit',
              {
                audit_state:this.form.audit_state,
                auditor:this.auditorId,
                audit_time:this.auditTime,
                audit_opinion:this.form.audit_opinion,
                evaplan_type_id:this.evaplan_type_id
              })
              .then((res)=>{
                console.log(res)
                if(res.data.code==0){
                    if(this.form.audit_state==2){
                      this.total_messages[0]={
                        mess_receiver:this.resultData.editor_id,
                        mess_type:18,
                        mess_link:'/editEvaluation'
                      };
                      this.totalOaMessage[0]={
                        mess_receiver:this.resultData.editor_name,
                        mess_type:18,
                        mess_link:'/editEvaluation'
                      };
                    }else if(this.form.audit_state==1){
                      this.total_messages[0]={
                        mess_receiver:this.resultData.editor_id,
                        mess_type:19,
                        mess_link:'/editEvaluation'
                      };
                      this.totalOaMessage[0]={
                        mess_receiver:this.resultData.editor_name,
                        mess_type:19,
                        mess_link:'/editEvaluation'
                      };
                    };
                    this.putUserNews(this.total_messages);
                    this.putMessage(this.totalOaMessage);
                  this.$alert(res.data.message,'提示',{
                    confirmButtonText: '确定',
                    callback: action => {
                      that.$router.go(-1)
                    }
                  });
                }else{
                  this.$alert(res.data.message,'提示',{
                    confirmButtonText: '确定',
                    callback: action => {
                      that.$router.go(-1)
                    }
                  });
                }
              })
          }else{
            console.log('error submit!!');
            return false;
          }
        })
      },
      //OA消息
      putMessage(OaMessage){
        this.axios.post('/api/v1/accout/externalmessagebatch',{
          total_messages:OaMessage
        }).then((res)=>{
          console.log(res.data)
        })
      },
      //user消息
      putUserNews(total_messages){
        this.axios.post('/api/v1/accout/usermessagebatch',
          {
            total_messages:total_messages
          },
        )
          .then((res)=>{
            if(res.data.code==0){
              this.$alert(res.data.message,'提示',function () {
                this.$router.go(-1)
              })
            }
          }).then((res)=>{

        })
          .catch((err)=>{
            this.$alert(err.message,'错误');
          })
      }

    },
    mounted(){
      this.initData();
    }
  })
</script>
<style scoped>
  .edit-container{
    padding:14px 10px 32px;
  }
  .edit-header{
    padding-bottom:12px;
    border-bottom:1px solid #eee;
  }
  .edit-content{


  }
  .evaluation-container  .e-confirm {
    margin-top:30px;
    margin-left: 255px;
    margin-bottom: 20px;
  }
  .evaluation-container >>> .e-confirm .el-button{

  }
  .evaluation-container{
    width: 100%;
    height: 100%;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 10px;
    background-color: white;
  }
  .evaluation-container .container  .el-dialog .el-form ul{
    height: 660px;
    overflow-y: scroll;
  }
  /*.oneoftwo{*/
    /*width: 50%;*/
    /*float: left;*/
  /*}*/
  .evaultion_area{
    margin-left: 28px;
    margin-right: 28px;
    background: #f2f5fc;
    height: 250px;
    padding-left: 120px;
    overflow: hidden;
    margin-top: 20px;

  }
  .evaultion_area .el-form{
    margin-top: 30px;
  }
  .evaultion_area .el-form .form-shenhe-menber .el-form-item{
    display: inline-block;
    width: 496px;

  }
  .evaultion_area .el-form .el-input{
    width: 378px;
    border: 1px solid #dfdfdf;
    background: white;
    border-radius: 2px;
  }
  .evaultion_area .el-form .el-input .el-input__inner{
    border:0
  }
  .evaultion_area .el-form .el-textarea{
    width: 882px;
    border: 1px solid #dfdfdf;
    background: white;
    border-radius: 2px
  }
  .evaultion_area >>> .el-form .el-textarea .el-textarea__inner{
    border: 0;
    resize: none;
  }
  @media screen and (max-width: 1400px) {
    .evaluation-container{
      padding: 6px;
    }
  }
</style>
